import json

from xjlibrary.our_file_dir import BaseDir
from xjlibrary.tools.excelpara import OpenpyxlUtils

filename = "F:\\fmzl20150301_20150318.xlsx"
outfilename = "F:\\excel.big_json"

xlsx_utils = OpenpyxlUtils()
xlsx_utils.set_wb_only_read(filename)
xlsx_utils.get_ws("发明公告日20150301_20150318")
print(xlsx_utils.max_column())
print(xlsx_utils.max_row())
list1 = list()
for cell in xlsx_utils.ws[1]:
    list1.append(cell.value)

string = ''
num = 0
for i in range(2, xlsx_utils.max_row() + 1):
    print(i)
    num += 1
    list2 = list()
    for cell in xlsx_utils.ws[i]:
        list2.append(cell.value)
    dicts = dict()
    for key, value in zip(list1, list2):
        dicts[key] = value
    print(dicts)
    encode_json = json.dumps(dicts, ensure_ascii=False)
    print(encode_json)
    dicts = json.loads(encode_json)
    print(dicts)
    string += encode_json + "\n"
    if num > 1000:
        BaseDir.single_add_file(outfilename, string)
        string = ''
        num = 0
BaseDir.single_add_file(outfilename, string)
